package main

import (
	"strings"

	"github.com/tealeg/xlsx"
)

func isRemote(str string) bool {
	var allchar string = "LTMB"
	for _, a := range allchar {
		for _, b := range allchar {
			newstr := "_" + string(a) + "T" + string(b)
			if strings.Contains(str, newstr) {
				return false

			}
		}
	}
	return true
}

func make_doc(sers []*Service, fstr string) {
	file := xlsx.NewFile()
	for _, service := range sers {
		if service != nil {
			fname := service.name
			if !isRemote(fname) {
				continue
			}
			//RealFname := fname + "(" +service.comment + ")"
			RealFname := fname
			sheet, err := file.AddSheet(RealFname)
			if err != nil {
				panic(err)
			}
			row := sheet.AddRow()
			row.SetHeightCM(1) //设置每行的高度
			row.AddCell().Value = "客户端到服务器消息"
			row.AddCell().Value = "cmd"
			row.AddCell().Value = "act"
			row.AddCell().Value = "proto"
			row.AddCell().Value = "    "
			row.AddCell().Value = "服务器到客户端消息"
			row.AddCell().Value = "cmd"
			row.AddCell().Value = "act"
			row.AddCell().Value = "proto"
			//var Allstr string
			//Allstr = Allstr + "\xEF\xBB\xBF"
			//Allstr = Allstr + "客户端到服务器消息;cmd;act;proto;;服务器到客户端消息;cmd;act;proto\n"
			for _, mothod := range service.methods {
				if mothod != nil {
					newRow := sheet.AddRow()
					AllName := fname + "_" + mothod.name
					var icmd string
					var iact string
					var ocmd string
					var oact string
					var input string
					var output string
					var icomment string
					var ocommnet string
					if mothod.input != "NULL" {
						input = mothod.input
						icmd = fname
						iact = AllName
						icomment = mothod.comment
					}
					if mothod.output != "NULL" {
						output = mothod.output
						ocmd = fname
						oact = AllName
						ocommnet = mothod.comment
					}
					newRow.AddCell().Value = icomment
					newRow.AddCell().Value = icmd
					newRow.AddCell().Value = iact
					newRow.AddCell().Value = input
					newRow.AddCell().Value = "    "
					newRow.AddCell().Value = ocommnet
					newRow.AddCell().Value = ocmd
					newRow.AddCell().Value = oact
					newRow.AddCell().Value = output
					//mstr := icomment + ";" +icmd+";"+iact+";"+input + ";;" + ocommnet + ";" + ocmd + ";" +oact +";" +output +"\n"
					//Allstr = Allstr + mstr
				}
			}
			//WriteFile(fstr+RealFname+".csv",[]byte(Allstr))
		}
	}
	err := file.Save(fstr + "足球小将消息汇总.xlsx")
	if err != nil {
		panic(err)
	}
}
